<?php
define("DB_FB_COMMENT_LOG_TABLE","fb_comment_log");

function _fb_comment_submissions_init($user_id, $comment_id){
	// check if there is any existing record
	$result = db_select(DB_FB_COMMENT_LOG_TABLE)
				->fields(DB_FB_COMMENT_LOG_TABLE, array('id', 'created'))
				->condition('user_id', $user_id,'=')
				->condition('comment_id', $comment_id,'=')
				->execute()
				->fetch();
	 if(!ISSET($result->id) || empty($result->id)){
	 	
		// first time comment, insert new record
		$query = db_insert(DB_FB_COMMENT_LOG_TABLE)
					->fields(array('user_id', 'comment_id', 'created', 'point_added'))
					->values(array($user_id, $comment_id, time(), 1));
		$sid = $query->execute();

		return true;

	}else{

		$midnight = strtotime('midnight');

		if($result->created < $midnight) {
			$update_query = db_update(DB_FB_COMMENT_LOG_TABLE)
							->fields(array(
						    'created' => time()
						  ))
						  ->execute();

			return true;
		}

		return false;
	}
	return false;
}